package com.naicha.wechat.wechat.businessservice;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.naicha.wechat.wechat.model.User;
import com.naicha.wechat.wechat.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * @author NaiCha
 * @date 2019/4/29 16:26
 * @description 微信业务逻辑service
 **/
@Service
@Transactional
public class WeChatBusinessService {

    @Autowired
    private IUserService userService;

    /**
     * 查询当前微信用户是否注册
     * @param openID
     * @param unionID
     * @return
     */
    public User getUserInfo(String openID, String unionID){
        LambdaQueryWrapper<User> queryWrapper = new QueryWrapper<User>().lambda()
                .eq(User::getOpenid, openID)
                .eq(User::getUnionid, unionID)
                .isNotNull(User::getUsername);
       return Optional.ofNullable(userService.getOne(queryWrapper)).orElse(null);
    }

}
